using System.Collections.Generic;

namespace Promote {
    public class SinglyLinkedList<T>
    {
        private Node<T> _head;
        private Node<T> _tail;
        private int _size;

        public SinglyLinkedList()
        {
            _head = null;
            _tail = null;
            _size = 0;
        }

        public int Add(T item)
        {
            Node<T> newNode = new Node<T>(item, null);
            if( _tail != null ) {
                _tail = (_tail._next = newNode);
            } else {
                _head = _tail = newNode;
            }
            return _size++;
        }

        public T Get(uint index)
        {
            Node<T> node = _head;
            for(uint ii = 0; ii != index; ++ii) {
                node = node._next;
            }
            return node._item;
        }

        private class Node<V>
        {
            public V _item;
            public Node<V> _next;

            public Node(V item, Node<V> next)
            {
                _item = item;
                _next = next;
            }
        }
    }
}

